package com.ruoyi.controller.tourism;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.tourism.BbRestaurantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 蚌埠餐饮模块
 * @date 2021/3/12 15:35
 */
@Controller
@RequestMapping("/BbRestaurant")
public class BbRestaurantController extends BaseController {

    @Autowired
    BbRestaurantService bbRestaurantService;

    private String prefix = "tourism/bbrestaurant";

    @GetMapping()
    public String bbRestaurant() {
        return prefix + "/bbrestaurantlist";
    }

    @RequestMapping("/listMonth")
    @ResponseBody
    public TableDataInfo listMonth(@RequestParam Map map) {
        startPage();
        return getDataTable(bbRestaurantService.findBbRestaurantMonthList(map));
    }

    @RequestMapping("/listDay")
    @ResponseBody
    public TableDataInfo listDay(@RequestParam Map map) {
        startPage();
        List<Map<String, Object>> list = bbRestaurantService.findBbRestaurantDayList(map);
        return getDataTable(list);
    }

    @GetMapping("/add")
    public String add(ModelMap mmap, String monthId) {
        mmap.put("monthId", monthId);
        return prefix + "/add";
    }

    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestParam Map map) {
        return toAjax(bbRestaurantService.addBbRestaurant(map));
    }

    @GetMapping("/edit/{id}")
    public String edit(ModelMap mmap, @PathVariable("id") String id) {
        mmap.put("data", bbRestaurantService.findBbRestaurantById(id));
        return prefix + "/edit";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map) {
        return toAjax(bbRestaurantService.editBbRestaurant(map));
    }

    @RequestMapping("/getLastDayData")
    @ResponseBody
    public Map getLastDayData(@RequestParam Map map) {
        return bbRestaurantService.getLastDayData(map);
    }
}
